package com.cpr.shop.config;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import com.cpr.shop.properties.AliyunSMSProperties;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author CPR
 * @Create 2025/1/24 17:51
 * @Version 1.0
 * @Description 阿里云SMS短信服务配置类
 */
@Configuration
@Slf4j
public class AliyunSMSConfiguration {

    @Resource
    private AliyunSMSProperties aliyunSMSProperties;

    @Bean
    public Client smsClient(){
        Config config = new Config();
        String accessKeyId = aliyunSMSProperties.getAccessKeyId();
        String accessKeySecret = aliyunSMSProperties.getAccessKeySecret();
        String endpoint = aliyunSMSProperties.getEndpoint();
        config.setAccessKeyId(accessKeyId);
        config.setAccessKeySecret(accessKeySecret);
        config.setEndpoint(endpoint);


        try {
            return new Client(config);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
